package com.mawendaxiong.blogprovider.blogMain.controller;


import com.mawendaxiong.blogprovider.blogMain.entity.BlogMain;
import com.mawendaxiong.blogprovider.blogMain.service.BlogMainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mawendaxiong
 * @since 2020-06-24
 */
@RestController
@RequestMapping("/blogMain")
@Slf4j
public class BlogMainController {
    @Autowired
    private BlogMainService service;

    @GetMapping("getBlogsByType")
    public List<BlogMain> getBlogsByType(String typeKid) {
        return service.getBlogsByType(typeKid);
    }

    @GetMapping("getBlogDetail")
    public BlogMain getBlogDetail(String blogKid) {
        return service.getBlogDetail(blogKid);
    }

    @GetMapping("getFakeBlogsByType")
    public List<BlogMain> getFakeBlogsByType() {
        List<BlogMain> list = new LinkedList<>();
        for (int i = 0; i < 10; i++) {
            BlogMain blogMain = new BlogMain();
            blogMain.setKid(UUID.randomUUID().toString().replace("-", ""));
            blogMain.setTitle("title"+i);
            blogMain.setKeyPoint("point"+i+",text"+i);
            list.add(blogMain);
        }
        return list;
    }

    @GetMapping("getFakeDetail")
    public BlogMain getFakeDetail() {
        BlogMain blogMain = new BlogMain();
        blogMain.setKid("testkid");
        blogMain.setKeyPoint("springcloud,nacos");
        blogMain.setTitle("testtitle");
        String main = "<p>这是正文，随便写点什么吧</P><h1>hahahahahahaah</h1>";
        blogMain.setMain(main);
        return blogMain;
    }
}
